﻿#define _CRT_SECURE_NO_WARNINGS 1
#include "game.h"

int main()
{
	int a = 0;
	srand(time(NULL));	//随机数种子
	do					//游戏主循环
	{
		Menu();			//打印一个简易的菜单
		printf("请选择-> ");
		scanf("%d", &a);
		system("cls");	//清空屏幕
		switch (a)
		{
		case 1:
			Game();		//游戏主程序
			break;
		case 0:
			printf("成功退出！\n");
			break;
		default:
			printf("非法输入！请重新输入：\n");
			break;
		}
	} while (a != 0);
	
	return 0;
}

void Game(void)
{
	char board[BOARD][BOARD];//玩家可以看到的棋盘
	char sboard[SBOARD][SBOARD];//隐藏的棋盘
	InitBoard(board, BOARD, '*');
	InitSboard(sboard, SBOARD, '0');
	PrintChess(board, BOARD);	//打印游戏棋盘

	//布雷
	Layout(sboard);

	int x = 0;
	int y = 0;

	int count = BOARD * BOARD - COUNT;
	while (count != 0)
	{
		printf("请输入你想要查看的点的坐标（用空格分隔）\n");
		scanf("%d%d", &x, &y);
		system("cls");
		if ((x >= 1) && (x <= BOARD) && (y >= 1) && (y <= BOARD))
		{
			//排雷
			if (sboard[x][y] == '1')
			{
				printf("挑战失败！\n");
				printf("雷区分布：\n");
				PrintsChess(sboard, SBOARD);	//打印游戏棋盘
				break;
			}
			DelRadae(board, sboard, x, y, &count);
			if (count == 0)
			{
				printf("挑战成功！\n");
				printf("雷区分布：\n");
				PrintsChess(sboard, SBOARD);	//打印游戏棋盘
				break;
			}
			PrintChess(board, BOARD);	//打印游戏棋盘
		}
		else
		{
			printf("非法输入！请重新输入！\n");
		}
	}
}